<?php
header('Content-Type: text/html;charset=UTF-8');
$link = mysqli_connect('localhost', 'root', '', 'simplyproject');

$event_id = $_POST['id'];
$result = mysqli_query($link, "SELECT * FROM event WHERE id_event = $event_id");

// Vérif si task appartient au projet

$event = mysqli_fetch_array($result);

?>

<div id="edit_task">

<span class="add_task">Add event ?</span>

<form action="" method="post">

	<label for="title_task">Title : </label>
	<input id="title_task" name="title_task" type="text" value="<?php echo $task['title']; ?>"/><br/><br/>

	<label for="start_date_task">Start date : </label>
	<?php
	$start_date = explode("-", $task['start_date']);
	?>
	<input id="start_date_task" name="start_date_task" type="text" value="<?php echo date("d/m/Y", mktime(0, 0, 0, $start_date[1], $start_date[2], $start_date[0])); ?>"/><br/><br/>
	<?php
	$end_date = explode("-", $task['end_date']);
	?>
	<label for="end_date_task">End date : </label>
	<input id="end_date_task" name="end_date_task" type="text" value="<?php echo date("d/m/Y", mktime(0, 0, 0, $end_date[1], $end_date[2], $end_date[0])); ?>"/><br/><br/>

	<label for="description_task">Description : </label><br/>
	<textarea id="description_task" name="description_task"><?php echo $task['description'] ?></textarea><br/><br/>

	<input type="hidden" name="id" value="<?php echo $task['id_task']; ?>" />

	<input type="submit" value="Envoyer" />
</form>


</div>


<div id="add_event">

    <form action="" method="post">

        <label for="title_event">Title : </label>
        <input id="title_event" name="title_event" type="text" value="<?php echo $event['title']; ?>"/><br/>

        <?php
	$start_date = explode("-", $event['start_date']);
	?>
        <label for="start_date_event">Start date : </label>
        <input id="start_date_event" name="start_date_event" type="text" value="<?php echo date("d/m/Y", mktime(0, 0, 0, $start_date[1], $start_date[2], $start_date[0])); ?>"/><br/>

        <label for="start_hour_event">Hour : </label>
        <select id="start_hour_event" name="start_hour_event">
                <option value="00">0h</option>
                <option value="01">1h</option>
                <option value="02">2h</option>
                <option value="03">3h</option>
                <option value="04">4h</option>
                <option value="05">5h</option>
                <option value="06">6h</option>
                <option value="07">7h</option>
                <option value="08">8h</option>
                <option value="09">9h</option>
                <option value="10">10h</option>
                <option value="11">11h</option>
                <option value="12">12h</option>
                <option value="13">13h</option>
                <option value="14">14h</option>
                <option value="15">15h</option>
                <option value="16">16h</option>
                <option value="17">17h</option>
                <option value="18">18h</option>
                <option value="19">19h</option>
                <option value="20">20h</option>
                <option value="21">21h</option>
                <option value="22">22h</option>
                <option value="23">23h</option>
        </select>

        <select id="start_min_event" name="start_min_event">
        
        <?php for($i = 0; $i < 12; $i++): ?>
            <?php 
                $val = str_pad($i*5, "0", STR_PAD_LEFT); 
                $start_hour = explode(":", $event['start_hour']);
                
                if($i*5 == $start_hour[1]){
                    $selected = "selected='selected'";
                }else{
                    $selected = "";
                }
            ?>
            
            <option <?php echo $selected; ?> value="<?php echo $val; ?>"><?php echo $val; ?></option>
                
        <?php endfor; ?>

        </select><br/>

        <?php
	$end_date = explode("-", $event['end_date']);
	?>
        <label for="end_date_event">End date : </label>
        <input id="end_date_event" name="end_date_event" type="text" value="<?php echo date("d/m/Y", mktime(0, 0, 0, $end_date[1], $end_date[2], $end_date[0])); ?>"/><br/>

        <label for="end_hour_event">Hour : </label>
        <select id="end_hour_event" name="end_hour_event">
                <option value="00">0h</option>
                <option value="01">1h</option>
                <option value="02">2h</option>
                <option value="03">3h</option>
                <option value="04">4h</option>
                <option value="05">5h</option>
                <option value="06">6h</option>
                <option value="07">7h</option>
                <option value="08">8h</option>
                <option value="09">9h</option>
                <option value="10">10h</option>
                <option value="11">11h</option>
                <option value="12">12h</option>
                <option value="13">13h</option>
                <option value="14">14h</option>
                <option value="15">15h</option>
                <option value="16">16h</option>
                <option value="17">17h</option>
                <option value="18">18h</option>
                <option value="19">19h</option>
                <option value="20">20h</option>
                <option value="21">21h</option>
                <option value="22">22h</option>
                <option value="23">23h</option>
        </select>

        <select id="end_min_event" name="end_min_event">
            
        <?php for($i = 0; $i < 12; $i++): ?>

            <?php
                $val = str_pad($i*5, "0", STR_PAD_LEFT);
                $end_hour = explode(":", $event['end_hour']);

                if($i*5 == $end_hour[1]){
                    $selected = "selected='selected'";
                }else{
                    $selected = "";
                }
            ?>

            <option <?php echo $selected; ?> value="<?php echo $val; ?>"><?php echo $val; ?></option>

        <?php endfor; ?>

        </select><br/>

        <label for="description_event">Description : </label>
        <textarea id="description_event" name="description_event"></textarea><br/>

        <label for="address_event">Location : </label><input id="address_event" name="address_event" type="text" /><br/>

        <div id="preview_google_maps">

        </div>

        <input type="submit" value="Envoyer" />
    </form>


</div>
